package com.example.tianxi.yuexiuhhpatient.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.tianxi.yuexiuhhpatient.Entity.HistoryEntity;
import com.example.tianxi.yuexiuhhpatient.Entity.RecommandDoctor;
import com.example.tianxi.yuexiuhhpatient.R;

import java.util.List;

/**
 * Created by tianxi on 16-3-5.
 */
public class RecommandDoctorAdapter extends BaseAdapter {

    private List<RecommandDoctor> lists;
    Context context;

    public RecommandDoctorAdapter(Context context,List<RecommandDoctor> list){
        this.context = context;
        this.lists = list;
    }

    @Override
    public int getCount() {
        return (lists==null)?0:lists.size();
    }

    @Override
    public Object getItem(int position) {
        return lists.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    public class ViewHolder{
        ImageView imageView;

        TextView textViewname;
        TextView textViewsex;
        TextView textViewage;
        TextView textViewtime;
        TextView textView01;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent){

        final RecommandDoctor doctor = lists.get(position);
        Log.v("name",doctor.name);
        ViewHolder viewHolder = null;
        if(convertView==null){
            Log.d("RecommandDoctorAdapter", "新建convertView,position=" + position);
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.recommanddoctor_listview_item, null);

            viewHolder = new ViewHolder();
            viewHolder.textViewname = (TextView)convertView.findViewById(
                    R.id.name);
            viewHolder.textViewsex = (TextView)convertView.findViewById(
                    R.id.cate);
            viewHolder.textViewage = (TextView)convertView.findViewById(
                    R.id.level);
            viewHolder.textViewtime = (TextView)convertView.findViewById(
                    R.id.where);
            viewHolder.textView01 = (TextView)convertView.findViewById(
                    R.id.goodat);


//            //动态增加1个ImageView
//            viewHolder.imageView = new ImageView(context);
//            LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(
//                    LinearLayout.LayoutParams.WRAP_CONTENT,
//                    LinearLayout.LayoutParams.WRAP_CONTENT);
//            mParams.gravity = Gravity.CENTER;
//            mParams.width=50;
//            viewHolder.imageView.setLayoutParams(mParams);
//            //这个ImageView放到ListView的第2列之后
//            ((LinearLayout)convertView).addView(viewHolder.imageView,2);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
            Log.d("MyBaseAdapter", "旧的convertView,position="+position);
        }

        //设置内容
        viewHolder.textViewname.setText(doctor.name);
        viewHolder.textViewsex.setText(doctor.cate);
        viewHolder.textViewage.setText(doctor.level);
        viewHolder.textViewtime.setText(doctor.where);
        viewHolder.textView01.setText(doctor.goodat);

        return convertView;
    }
}